package com.googlecode.spreadit.activity;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.googlecode.spreadit.R;
import com.googlecode.spreadit.util.ListViewUtil;

/**
 * This {@link ListActivity} relates to the {@link R.layout#main "Main" screen}.
 * 
 * @author Markus L. Dechert (markus.dechert@googlemail.com)
 */
public class Main extends ListActivity implements OnItemClickListener {

	private static int[] MENU_ENTRIES = { R.string.main_menu_managerules,
			R.string.main_menu_showhistory, R.string.main_menu_about };

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);

		// Add list entries
		ListAdapter menuItemListAdapter = ListViewUtil
				.createListAdapterByResourceStrings(this, MENU_ENTRIES);
		setListAdapter(menuItemListAdapter);

		ListView lv = (ListView) findViewById(android.R.id.list);
		lv.setOnItemClickListener(this);

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {

		switch ((int) id) {
		case 0: // Manage rules
			Intent manageRulesScreen = new Intent(ManageRules.HANDLER_ID);
			startActivity(manageRulesScreen);
			break;
		case 1: // Show history
			// TODO: implement history screen
			Toast.makeText(this, "Show history - not implemented yet",
					Toast.LENGTH_LONG).show();
			break;
		case 2: // -> About
			Intent aboutScreen = new Intent(About.HANDLER_ID);
			startActivity(aboutScreen);
			break;
		}
	}
}